package com.samphanie.admin.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.samphanie.admin.modules.sys.service.ISysClientService;
import com.samphanie.mbg.mapper.sys.SysClientMapper;
import com.samphanie.mbg.model.sys.SysClient;
import com.samphanie.mbg.utils.PageUtils;
import com.samphanie.security.domain.OauthClient;
import org.springframework.beans.BeanUtils;
import org.springframework.security.oauth2.provider.NoSuchClientException;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * 客户端Service业务层处理
 *
 * @author zsy
 * @date 2021-06-11
 */
@Service
public class SysClientServiceImpl extends ServiceImpl<SysClientMapper, SysClient> implements ISysClientService {

    /**
     * 查询客户端信息
     * @param clientId 客户端ID
     * @return OauthClient
     */
    @Override
    public OauthClient loadClientByClientId(String clientId) {
        SysClient sysClient = getOne(new LambdaQueryWrapper<SysClient>().eq(SysClient::getClientId, clientId));
        return Optional.ofNullable(sysClient).map(client -> {
            OauthClient oauthClient = new OauthClient();
            BeanUtils.copyProperties(client, oauthClient);
            oauthClient.setAutoapprove(client.getAutoApprove());
            return oauthClient;
        }).orElse(null);
    }
}
